package com.service.impl;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.dao.TopicTableDao;
import com.service.TopicTableService;
import com.util.CacheUtil;
import com.util.LoggerUtil;
import com.util.Redis;

@Component
public class TopicTableServiceImpl implements TopicTableService{
	public static final Logger logger=Logger.getLogger(TopicTableServiceImpl.class);
	@Autowired
	private TopicTableDao topicTableDao;

	@Override
	public Map<String, Object> findLineTables(JSONObject logs) {
		Map<String, Object> map=new HashMap<>();
		String keys =logs.getString("keys");
		try {
			Map<String, Object> lineTables=topicTableDao.findLineTables();
			map.put("result", "success");
			map.put("rows", lineTables);
			if(StringUtils.isNotEmpty(keys)){
				Redis.setRedisData(keys, CacheUtil.getValue(map));
			}
			LoggerUtil.backlogsSuccess(logs, logger);
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
		}
		return map;
	}
	
}
